function array_search (needle, haystack, argStrict) {
  // http://kevin.vanzonneveld.net
  // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // + input by: Brett Zamir (http://brett-zamir.me)
  // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // * example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
  // * returns 1: 'surname'
  // * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
  // * example 2: var ordered_arr = array({3:'value'}, {2:'value'}, {'a':'value'}, {'b':'value'});
  // * example 2: var key = array_search(/val/g, ordered_arr); // or var key = ordered_arr.search(/val/g);
  // * returns 2: '3'

  var strict = !!argStrict,
    key = '';

  if (haystack && typeof haystack === 'object' && haystack.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
    return haystack.search(needle, argStrict);
  }
  if (typeof needle === 'object' && needle.exec) { // Duck-type for RegExp
    if (!strict) { // Let's consider case sensitive searches as strict
      var flags = 'i' + (needle.global ? 'g' : '') +
            (needle.multiline ? 'm' : '') +
            (needle.sticky ? 'y' : ''); // sticky is FF only
      needle = new RegExp(needle.source, flags);
    }
    for (key in haystack) {
      if (needle.test(haystack[key])) {
        return key;
      }
    }
    return false;
  }

  for (key in haystack) {
    if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
      return key;
    }
  }

  return false;
}
function changepage(pagerow)
{
         $('.pagenumber').removeClass('active');
         $('#pagenum-'+pagerow).addClass('active');
         $(".pagedataall").hide();
         $("#pagerow-"+pagerow).show();
}
            $(function() {
                //left value = img width + margin-right
                $(".dotOutB").click(function() {
                    $(".dotOutB").addClass("dotInB").not(this).removeClass("dotInB");
                    switch (true) {
                      case $(this).hasClass('dotBP1'):
                            $(".wrapTumbnlBnDef").animate({
                                left: '0'
                            }, 700 );
                            break;
                      case $(this).hasClass('dotBP2'):
                            $(".wrapTumbnlBnDef").animate({
                                left: '-805px'
                            }, 700 );
                            break;
                      case $(this).hasClass('dotBP3'):
                            $(".wrapTumbnlBnDef").animate({
                                left: '-1610px'
                            }, 700 );
                            break;
                      case $(this).hasClass('dotBP4'):
                            $(".wrapTumbnlBnDef").animate({
                                left: '-2415px'
                            }, 700 );
                            break;
                    }
                 });
                 
                 $(".wrapCloseIcon").click(function() { 
                    $(".wrpShowlanding").hide();
                });
            });
            
             function showdatapopup(bookid)
            {
             getCORS(serviceinfo+'getbook',
            {
            bookid:bookid
            
            },function(data) {
            
            //console.log(arraybook);
            var key=array_search(bookid,arraybook);
            $("#lefticon").show();
            $("#righticon").show();
            //var prev=0
            
            if(parseInt(key,10)==(arraybook.length-1))
            {
            
            $("#righticon").hide();
            
            }
           
            
            
          
            
            if(parseInt(key,10)==0)
            {
            
            $("#lefticon").hide();
            
            }
            //console.log(key);
          //  console.log(arraybook);
          //  console.log(arraybook.length-1);
            $("#lefticon").attr("onclick","showdatapopup("+arraybook[(parseInt(key,10)-1)]+")");
            $("#righticon").attr("onclick","showdatapopup("+arraybook[(parseInt(key,10)+1)]+")");
            
            
            //console.log(key);
            
            $("#text-username").html(data.data.book.username);
            $("#text-updatedate").html(data.data.book.updatedate2);
            $("#text-title").html(data.data.book.topic);
            $("#text-description").html(data.data.book.title);
            $("#text-date").html(data.data.book.datedata);
            $("#text-time").html(data.data.book.time);
            $("#text-place").html(data.data.book.place);
            //$("#text-place").html(data.data.book.place);
            
            var code="";
            var numsort=1;
            $.each( data.data.book.filearr,function(key, value){
            
            code += '<div class="wrpRl">\n';
            code+='<div class="orderSB" >'+numsort+'</div>\n';
            code += '<div class="wrpImgSB"><img width="145" height="110"  src="'+value.img+'" ></div>\n';
            code +='<div class="wrpDetailSB">\n';
            code += '<div class="nameSB"><a href="javascript:void(0)" title="'+value.name+'" >'+value.name+'</a></div>\n';
            code += '<div class="fileSizeSB">'+value.filesize+'</div>\n';
            code += '<div class="fileTypeSB" >'+value.filetype+'</div>\n';
            code +='<a href="'+value.file+'" target="_blank" class="btnLoad">Download</a>\n';
            code +='</div>\n';
            code += '</div>';
            numsort++;
             
            });
            
            $("#booktable").html(code);
            
           // $("#text-booktype").html(data.data.book.booktype);
//            $("#text-filetype").html('<a href="'+fileinfo+'/'+data.data.book.shelfid+'/'+data.data.book.bookid+'/'+data.data.book.bookid+data.data.book.filetype2+'">'+data.data.book.filetype+'</a>');
//            $("#text-filesize").html(data.data.book.filesize);
//            $("#text-price").html(data.data.book.price+"$");
            
          //  $("#text-description").html(data.data.book.description);
          //  $("#linkQRCode").attr("href","http://api.qrserver.com/v1/create-qr-code/?data="+encodeURIComponent(serviceinfo+'redirectpage?shelfid='+data.data.book.shelfid+'&bookid='+data.data.book.bookid+'&nojson=1')+'&size=540x540');
           // $("#editQRCode").attr("src","http://api.qrserver.com/v1/create-qr-code/?data="+encodeURIComponent(serviceinfo+'redirectpage?shelfid='+data.data.book.shelfid+'&bookid='+data.data.book.bookid+'&nojson=1')+'&size=200x200');
            
            //var krow=1;
//            var strscreenshot="";
//            var strscreenshot2="";
//            var rowdata="";
//            var dotin="";
//            for (var instance in data.data.screenshot) {
//   
//            rowdata=data.data.screenshot[instance];
//            strscreenshot+='<img class="imgGal imgGal'+krow+'" src="'+imginfo+'/'+data.data.book.shelfid+'/'+data.data.book.bookid+'/banner/'+rowdata.photo+'">';
//            dotin="";
//            if(krow==1)
//            {
//            dotin="dotInS";
//            
//            }
//            strscreenshot2+='<div class="dotOutS dotSP'+krow+' '+dotin+'"></div>';
//            krow++;
//            
//            
//            
//            }
            
            
            $("#text-gallery").hide();
            $("#text-dotout").hide();
            
            
            
            $("#edtibookset").hide();
            if(cookieoauth==data.data.book.oauth)
            {
            $("#edtibookset").attr("onclick","edtibookset("+data.data.book.bookid+")");
            $("#edtibookset").show();
            }else if(data.data.book.admin==1)
            {
            
             $("#edtibookset").attr("onclick","edtibookset("+data.data.book.bookid+")");
            $("#edtibookset").show();
            
            }
            // $(".dotOutS").click(function() {
//                    $(".dotOutS").addClass("dotInS").not(this).removeClass("dotInS");
//                    switch (true) {
//                      case $(this).hasClass('dotSP1'):
//                            $(".ctnGallery").animate({
//                                left: '0'
//                            }, 700 );
//                            break;
//                      case $(this).hasClass('dotSP2'):
//                            $(".ctnGallery").animate({
//                                left: '-670px'
//                            }, 700 );
//                            break;
//                      case $(this).hasClass('dotSP3'):
//                            $(".ctnGallery").animate({
//                                left: '-1340px'
//                            }, 700 );
//                            break;
//                      case $(this).hasClass('dotSP4'):
//                            $(".ctnGallery").animate({
//                                left: '-2010px'
//                            }, 700 );
//                            break;
//                    }
//                 });
            
            $(".wrpShowlanding").show();
            
            
            //$("#text-booktype").html(data.book.title);
//            $("#text-booktype").html(data.book.title);
//            $("#text-booktype").html(data.book.title);
//            $("#text-booktype").html(data.book.title);
            
            }
            );
             
            }
            function edtibookset(bookid)
            {
            location.href=baseinfo+'/addbook?bookid='+bookid+'&shelfid='+shelfid;
            
            }
            
        